﻿using System.Drawing;
using System.Windows.Forms;

namespace TimeLineControl
{
    public partial class TimeLineProgressBar : UserControl
    {
        public TimeLineProgressBar()
        {
            InitializeComponent();
        }

        protected Color Barcolor = SystemColors.Highlight;

        public float Minimum { get; set; }
        public float Maximum { get; set; }

        public override Color ForeColor
        {
            get
            {
                return Barcolor;
            }
            set
            {
                Barcolor = value;
                Invalidate();
            }
        }

        protected float Valueprogress;

        public float Value
        {
            get
            {
                return Valueprogress;
            }
            set
            {

                if (value < Minimum) value = Minimum;
                if (value > Maximum) value = Maximum;
                Valueprogress = value;
                Invalidate();
            }
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Brush b = new SolidBrush(Barcolor);

            // calculate width of progress bar filler in pixels
            var width = (int)(((Valueprogress / Maximum) * Width));

            // draw the progress bar
            e.Graphics.FillRectangle(b, 0, 0, width, Height);

            b.Dispose();

        }
    }
}
